import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useSearchStore = defineStore(
  'search',
  () => {
    const searchHistory = ref([])

    const getSearchHistory = () => { return searchHistory.value }

    const addSearchHistory = (key) => { searchHistory.value.unshift(key) }

    return { searchHistory, getSearchHistory, addSearchHistory }
  },
  {
    persist: {
      key: 'search', // 指定存储的 key
      storage: localStorage // 指定存储方式，默认是 localStorage
    }
  }
)
